home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11858 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  101 lines

  1. Path: csus.edu!csus
  2. From: sac46826@csus.edu (Mike Billard)
  3. Newsgroups: comp.lang.c++
  4. Subject: MSVC++4.0 compile error- help needed
  5. Date: Sat, 16 Mar 96 18:16:23 GMT
  6. Organization: California State University Sacramento
  7. Message-ID: <4if0if$m68@news.csus.edu>
  8. NNTP-Posting-Host: @u0108-p20.dialin.csus.edu
  9. X-Newsreader: News Xpress 2.0 Beta #0
  10.  
  11. Please help!  I am a very frustrated begenning C++ programmer trying to use 
  12. MSVC++ 4.0.  I am trying to follow good programming practice by declaring my 
  13. objects and functions in a header file, but I'm having serious trouble.  The 
  14. stuff I'm doing is very simple and shown below:
  15.  
  16. **** header file CTest.h****
  17. class CTest
  18. {
  19.   private:
  20.     int I;
  21.   public:
  22.     CTest();
  23.     CTest(int ToI);
  24.     void SetI(int ToI);
  25.     int GetI();
  26.     };
  27.  
  28. **** Implementation file CTest.cpp ****
  29. #include "CTest.h"
  30.  
  31. CTest::CTest(){};
  32. CTest::CTest(int ToI)
  33.  {
  34.     I = ToI;
  35.     };
  36.  
  37. void CTest::SetI(int ToI)
  38. {
  39.   I = ToI;
  40.   };
  41.  
  42. int CTest::GetI()
  43. {
  44.   return I;
  45.   };
  46.  
  47. **** main file Main.cpp ****
  48. #include "CTest.h"
  49. #include <iostream.h>
  50.  
  51. void main()
  52. {
  53.   CTest TestObj;
  54.   TestObj.SetI(9);
  55.   cout << TestObj.GetI();
  56.   };
  57.  
  58.   This is very basic stuff, or so I thought.  If I add the Main.cpp and the 
  59. CTest.cpp to the console mode project and build it, MSVC++ runs fine, and I 
  60. get no errors.
  61. However, when I create a Windows program (MDI, SDI, Dialog-based) and add the 
  62. CTest.cpp to the project and the CTest.h to a simple dialog class that I 
  63. create, upon building the project I receive the following message:
  64.  
  65. :\Projects\test\CTest.cpp(23) : fatal error C1010: unexpected end of file 
  66. while looking for precompiled header directive
  67.  
  68.  If I DO NOT add the CTest.cpp to the project, I receive the following errors:
  69.  
  70. MyDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall 
  71. CTest::SetI(int)"(?SetI@CTest@@QAEXH@Z)
  72. MyDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall 
  73. CTest::CTest(void)"(??0CTest@@QAE@XZ)
  74.  
  75.   From what I can tell, the compiler cannot or will not find the 
  76. #include "CTest.h"  directive when I have included the cpp file.  I have 
  77. placed the two CTest files (CTest.h and CTest.cpp) in the project directory, 
  78. added the project directory to the list of directories (under Options) and yet 
  79. it STILL won't find the header file.  
  80.   I have tried to follow the examples of other files which are included in the 
  81. project, such as the dialog.h and dialog.cpp (which have no problems 
  82. building), and yet I continue to get the same error
  83. .
  84. Can someone please tell me what I'm doing wrong?!!!  
  85.  
  86.  Before abandoning my investment and simply use Delphi 2.0, I'd like to at 
  87. least try to figure out what my mistake is, if any.  Again, I am relatively 
  88. new to programming in C++ so I may be missing something really basic here.  
  89. Readers should note that I am using the default factory settings that MSVC++ 
  90. uses in things like the options, environment, etc.  The ONLY change I've made 
  91. is to smart indent my right block bracket so it lines up with the code, but I 
  92. doubt that is the cause of my problem.  Further, I have downloaded and 
  93. installed the latest patches.
  94.  
  95.   Your help is appreciated.
  96.  
  97.  
  98. -Mike Billard
  99.  
  100. email: billardm@csus.edu
  101.